# -*- coding: utf-8 -*-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <style type="text/css">
        body, h1 { margin:0;padding:0; } /* needed for known issue with Dom.getXY() in safari for absolute elements in positioned containers */ 
        .sl .space-line {clear:both;}
        .sp{float:left; width:50px;}
        textarea {border: 0px solid black; width:650px; height:275px;margin:0;padding:0;
                font-family:inherit; font-size:inherit;
                overflow:visible;}
        textarea[disabled="disabled"]
                {color:black;
                font-family:inherit; 
                width:650px;
                font-size:inherit;}

        .un .username{font-family:inherit; font-size:inherit;background-color:lightgrey;}
        .box    {background-color:lightgrey;
                width:650px;
                font-size:10pt;
                font-family:monospace;}
        a:link {text-decoration:none;}
        a:visited {text-decoration:none;}
        a:active  {text-decoration:none;}
        #name{
            font-family:inherit; font-size:inherit;
            border: 1px solid black;
        }
    </style>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>YTalk online - room list</title>

    <script type="text/javascript" src="http://comet.${TOPDOMAIN}/_/comet.js"></script>
    <script type="text/javascript" src="/_/comet-helper.js"></script>
</head>
<body>
    <form action="." method="get" id='formanme' >
    <h2>You are known as <input  type="text" name="username" value="${username}" onblur="document.getElementById('formanme').submit(); " />
    <input type="submit" value="ok" />
    </h2>
    </form>
    <button onclick="new_room()">New room</button>
    <div style="display:none;">
        <form action="." method="post" id="room_form" autocomplete="off">
            <input type="text" name="username" value="${username}" />
            <input type="text" id="room_name" name="room_name" value="" />
        </form>
    </div>
    <script>
        document.domain = extract_xss_domain(document.domain);
        function new_room(){
            var name = prompt('Enter new room name:', '${new_room_name}');
            if(!name){
                return;
            }
            document.getElementById('room_name').value = name;
            document.getElementById('room_form').submit();
        }
    </script>
    
    

    <script>
        max_id = ${max_id};
        
        scheduled_refresh = false;
        function user_comet_callback(id, author, data) {
            var a        = data.split(' ');
            /* user event */
            if(author != 'admin')
                return;
            
            var obj_id   = a[1]
            var obj_body = a.slice(2).join(' ');
            try{
                document.getElementById(obj_id).innerHTML = obj_body;
            }catch(e){
                if(!scheduled_refresh ){
                    try{
                    ajax_crossdomain('http://${DOMAIN}/_/crossajax.html?a=a', 'GET', '/ytalk/contents?a=' + Math.random(), function (xhr) {
                            if(xhr.readyState != 4)
                                return;
                            scheduled_refresh = false;
                            if(xhr.status != 200)
                                return;
                            document.getElementById('bigbox').innerHTML = xhr.responseText;
                        }, null );
                    }catch(e){
                        /* fuck webkit */
                    }
                    kill_load_bar();
                    scheduled_refresh = true;
               }
            }
        }
        
        function user_channel_callback(channel_id_changed, json){
            document.getElementById('bigbox').innerHTML = json.bigbox;
        }
        
        generate_channel_id_updater('http://comet.${TOPDOMAIN}/_/iframe.html?a=a', '${username}', user_comet_callback, user_channel_callback);

    </script>

    <div id="bigbox">
        <%include file="ytalk_list_part.html" />
    </div>

</body>
</html>


